﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace cludg.Services.Security.ValidateUserStrategies
{
    using Repository.Security;

    internal class ThirdParty : ValidateUserStrategy<Principals.ThirdParty>
    {
        protected override string DoValidateUser(ISecurityRepository repository, Principals.ThirdParty principal)
        {
            UserSecurityInfo info = null;
            info = repository.GetUserSecurityInfoByThirPartyIdent(principal.Ident);
            if (info == null)
                throw new UserNotFoundError(principal, "Нет пользователя");

            if (info.State == UserSecurityInfo.UserState.NeedActivation)
                throw new UserNeedActivationError(principal, "Пользователь не активирован");

            if (info.LoginType != UserSecurityInfo.UserLoginType.ThirdParty)
                throw new ValidateUserError(principal, "Не может входить через сторонний провайдер");

            return info.Id;
        }
    }
}
